package com.example.lin.week2project.utils;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

public class FileUtils {



    public static boolean writeText2File(File to, String text) {
        try (FileWriter fw = new FileWriter(to);) {
            fw.write(text);
            return true;
        } catch (IOException e) {
            e.printStackTrace();
        }
        return false;
    }



    public static String readTextFromFile(File from) {
        try (BufferedReader br = new BufferedReader(new FileReader(from));) {
            String line;
            StringBuilder sb = new StringBuilder();
            while ((line = br.readLine()) != null) {
                sb.append(line).append("\n");
            }
            sb.delete(sb.length() - 1, sb.length());
            return sb.toString();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }

}
